package com.nhim.cms.admin.server;

import java.util.ArrayList;
import java.util.List;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.nhim.cms.CustomWidgetProperty;
import com.nhim.cms.admin.client.rpc.CustomWidgetPropertyService;
import com.nhim.cms.admin.shared.CustomWidgetPropertyProxy;
import com.nhim.cms.jaxws.CustomWidgetPropertyWS;
import com.nhim.cms.util.AppContext;

public class CustomWidgetPropertyServiceImpl extends RemoteServiceServlet
		implements CustomWidgetPropertyService {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public ArrayList<CustomWidgetPropertyProxy> getProperties(String className) {
		
		ArrayList<CustomWidgetPropertyProxy> result = new ArrayList<CustomWidgetPropertyProxy>();
		try {
			CustomWidgetPropertyWS client = (CustomWidgetPropertyWS) AppContext
					.getApplicationContext().getBean("customWidgetPropertyWS");
			if (client != null) {
				List<CustomWidgetProperty> cwgProperties = client.getProperties(className);
				if (cwgProperties != null && cwgProperties.size() > 0) {
					for (CustomWidgetProperty cwg : cwgProperties) {
						result.add(ToProxy(cwg));
					}
				}
			}
		} catch (Exception ex) {
			System.out.println(ex.getMessage());

		}
		return result;

	}

	private CustomWidgetPropertyProxy ToProxy(CustomWidgetProperty cProperty) {
		return new CustomWidgetPropertyProxy(cProperty.getName(), cProperty
				.getDataType().toString(), cProperty.getDescription(),
				cProperty.getDisplayType().toString(),
				cProperty.getDisplayValues());

	}

}
